﻿<form id="dorefund" class="tableform" method='post' action='index.php?ctl=admin_refund_apply&app=ome&act=accept&p[0]=<{$refund.apply_id}>&finder_id=<{$env.get.finder_id}>'>
<input type='hidden' name='api_fail_flag' id='api_fail_flag' value='<{$api_fail_flag}>' />
<input type='hidden' name='return_id' id='return_id' value='<{$return_id}>' />
<input type='hidden' name='api_refund_request' id='api_refund_request' value='false' />
<input type='hidden' name='shop_id' id='shop_id' value='<{$shop_id}>'>
<input type='hidden' name='order_id' id='order_id' value='<{$order.order_id}>'>

  <div class="division">
    <table width="100%" cellspacing="0" cellpadding="0" border="0">
      <tr>
        <th><{t}>平台订单号:<{/t}></th>
        <td><{$order.order_bn}> 【<{$pay_status[$order.pay_status];}>】</td>
        <th><{t}>下单日期:<{/t}></th>
        <td><{$order.createtime|cdate:'SDATE_STIME'}></td>
      </tr>
      <tr>
        <th><{t}>订单金额:<{/t}></th>
        <td><{$order['total_amount']}></td>

        <th><{t}>已付金额:<{/t}></th>
        <td><{$order.payed}></td>
      </tr>
      <tr>
        <th><{t}>退款类型: <{/t}></th>
        <td><{input type="radio" name="pay_type" options=$typeList value=$pay_type vtype='requiredradio'}></td>
        <th><{t}>退款支付方式:<{/t}></th>
        <td>
        <{if $payment}>
	    <{if $node_id}>
	    <select id='payment' name='payment' vtype='required'>
	        <{if $payment_id}>
	          <{foreach from=$order_paymentcfg key=key item=item}>
	            <option value="<{$item.id}>"><{$item.custom_name}></option>
	          <{/foreach}>
	        <{/if}>
	    </select>
	    <{else}>
	        <{input type="select" id="payment" name='payment' rows=$payment valueColumn="id" labelColumn="custom_name" value=$payment_id vtype='required'}>
	    <{/if}>
	    <{else}>
	    <select id='payment' name='payment'>
	    </select>
	    <em class="red">请先添加或同步前端店铺支付方式</em>
	    <{/if}>
        </td>
      </tr>
      <tr>
        <th><{t}>退款银行:<{/t}></th>
        <td colspan="3"><{input type='text' id='payBank' name='bank' value=$refund.bank width="140"}> <{input id="selectAccount" type="select" name='select_account' options=$pay_account  value=''}></td>
      </tr>
      <tr>
        <th><{t}>退款帐号:<{/t}></th>
        <td><{input type='text' name='account' id='payAccount' value=$refund.account width="140"}></td>
        <th><{t}>收款帐号:<{/t}></th>
        <td><{input type='text' name='pay_account' value=$refund.pay_account width="80"}></td>
      </tr>
      <tr>
        <th><{t}>退款金额:<{/t}></th>
        <td><{$refund.money}><{input type='hidden' id='money' name='money' value=$refund.money width="140"}></td>
      </tr>
      <tr>
        <th><{t}>第三方交易号:<{/t}></th>
        <td><{input type='text' id='trade_no' name='trade_no'  width="140"}></td>
      </tr>
    </table>
  </div>
  <div class="table-action">
    <{button type="button" label="提交" class="btn-primary" id="submit_btn"}>
  </div>
</form>
<script>

$$('input[name^=pay_type]').addEvent('click', function(){
    var order_id = $('order_id').value, shop_id = $('shop_id').value, pay_type = this.value;
    W.page('index.php?app=ome&ctl=admin_finance&act=payment_by_pay_type&p[0]='+order_id+'&p[1]='+shop_id+'&p[2]='+pay_type,{update:$('payment')});
});

$('submit_btn').addEvent('click', function(){
    var api_fail_flag = 'false',api_refund_request;
    api_fail_flag = $('api_fail_flag').value;
    if (api_fail_flag == 'true'){
        if (confirm("该订单上次同步退款失败，此次支付是否仍然发送同步请求?")){
            api_refund_request = 'true';
        }else{
            api_refund_request = 'false';
        }
        $('api_refund_request').set('value', api_refund_request);
    }else{
    	<{if $order.pay_status == 7}>
	        if (confirm("上次退款单同步请求超时，确定不同步直接退款吗?")){
	            $('api_refund_request').set('value', 'false');
	        }else{
	            return false;
	        }
        <{/if}>
    }
    $('dorefund').fireEvent('submit',{stop:function(){}});
});

$('selectAccount').addEvent('change', function(e){
    e=new Event(e);
    var ipt=e.target;
    var str = ipt.value;
    var aItems = str.split('-');
    $('payBank').value = aItems[0];
    $('payAccount').value = aItems[1];
});

$('dorefund').store('target',{
	onRequest:function(){
        $('submit_btn').set('disabled', 'true');
        $('submit_btn').getElements('span')[1].set('text','正在提交');
    },
    onComplete:function(jsontext){
      //jsontext = jsontext.replace(/[\r\n]+/img, ' ');
      var json = Json.evaluate(jsontext);
      if (typeof(json.error) == 'undefined'){
        if (typeof(json.error) == 'undefined'){
          $('dorefund').getParent('.dialog').retrieve('instance').close();
          parent.finderGroup['<{$finder_id}>'].refresh.delay(400,parent.finderGroup['<{$finder_id}>']);
        }
      }else{
    	  $('submit_btn').set('disabled', '');
          $('submit_btn').getElements('span')[1].set('text','提交');
      }
    }
});
</script>
